package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.PersonalityTypeMapper;
import com.tanhua.model.domain.PersonalityType;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description：test
 * @Create by： 张会豪
 * @Date：2021/11/7 20:44
 */
@DubboService
public class PersonalityTypeApiImpl implements PersonalityTypeApi {

    @Autowired
    private PersonalityTypeMapper personalityTypeMapper;

    //根据用户总分在表中查询最新数据，返回对应人格类型id
    public Long findByScore(Integer score) {
        LambdaQueryWrapper<PersonalityType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.le(PersonalityType::getScoreMin, score).ge(PersonalityType::getScoreMax, score);
        PersonalityType personalityType = personalityTypeMapper.selectOne(queryWrapper);
        return personalityType.getId();
    }

    //根据id查询对象
    public PersonalityType findById(Long id) {
        LambdaQueryWrapper<PersonalityType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PersonalityType::getId, id);
        return personalityTypeMapper.selectOne(queryWrapper);
    }
}
